<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>初始化 cURL 会话</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.curl-init" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_init</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">curl_init</span> &mdash; <span class="dc-title">初始化 cURL 会话</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.curl-init-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>curl_init</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$url</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
  ] ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   初始化新的会话，返回 cURL 句柄，供<span class="function"><a href="curl_setopt.html" class="function">curl_setopt()</a></span>、 <span class="function"><a href="curl_exec.html" class="function">curl_exec()</a></span> 和 <span class="function"><a href="curl_close.html" class="function">curl_close()</a></span> 函数使用。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.curl-init-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">url</code></dt>

     <dd>

      <p class="para">
       如果提供了该参数，<strong><code>CURLOPT_URL</code></strong> 选项将会被设置成这个值。你也可以使用<span class="function"><a href="curl_setopt.html" class="function">curl_setopt()</a></span>函数手动地设置这个值。
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        如果设置了 <a href="ini.core.html#ini.open-basedir" class="link">open_basedir</a>，<em>file</em> 协议会被 cURL 禁用。
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl-init-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果成功，返回 cURL 句柄，出错返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.curl-init-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5242">
    <p><strong>Example #1 
     初始化新的 cURL 会话并获取一个网页
    </strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;创建一个新cURL资源<br /></span><span style="color: #0000BB">$ch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;设置URL和相应的选项<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_URL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"http://www.example.com/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_HEADER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;抓取URL并把它传递给浏览器<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;关闭cURL资源，并且释放系统资源<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.curl-init-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="curl_close.html" class="function" rel="rdfs-seeAlso">curl_close()</a> - 关闭 cURL 会话</span></li>
    <li class="member"><span class="function"><a href="curl_multi_init.html" class="function" rel="rdfs-seeAlso">curl_multi_init()</a> - 返回一个新cURL批处理句柄</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>